﻿using NewsMine.DataManagers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NewsMine.DomainObjects;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;

namespace NewsMine.DataManagers.Tests
{
    
    
    /// <summary>
    ///This is a test class for ChannelManagerTest and is intended
    ///to contain all ChannelManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ChannelManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ChannelManager Constructor
        ///</summary>
        [TestMethod()]
        public void ChannelManagerConstructorTest()
        {
            ChannelManager target = new ChannelManager();
            Assert.Inconclusive("TODO: Implement code to verify target");
        }

        /// <summary>
        ///A test for AddChannel
        ///</summary>
        [TestMethod()]
        public void AddChannelTest()
        {
            ChannelManager target = new ChannelManager(); 
            Channel channel = new Channel { Name="english",Query="language:english",ImageUrl="http://example.com/test.jpg"};
            target.AddChannel(channel);

            Channel expected = target.GetChennelByName(channel.Name);


            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(Channel));

            target.DeleteChannel(channel.Name);

            expected = target.GetChennelByName(channel.Name);

            Assert.IsNull(expected);
        }

     

        [TestMethod()]
        public void DeleteAllFromChannelStore()
        {
            ChannelManager target = new ChannelManager();

            target.DeleteChannel("telugu");
            target.DeleteChannel("english");

            
        }
        /// <summary>
        ///A test for DeleteChannel
        ///</summary>
        [TestMethod()]
        public void DeleteChannelTest()
        {
            ChannelManager target = new ChannelManager();
            Channel channel = new Channel { Name = "english", Query = "language:english", ImageUrl = "http://example.com/test.jpg" };
            target.AddChannel(channel);

            Channel expected = target.GetChennelByName(channel.Name);


            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(Channel));

            target.DeleteChannel(channel.Name);

            expected = target.GetChennelByName(channel.Name);

            Assert.IsNull(expected);
        }

        /// <summary>
        ///A test for DeleteChannel
        ///</summary>
        [TestMethod()]
        public void DeleteChannelTest1()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            Channel channel = null; // TODO: Initialize to an appropriate value
            target.DeleteChannel(channel);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for GetAllChannels
        ///</summary>
        [TestMethod()]
        public void GetAllChannelsTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            List<Channel> expected = null; // TODO: Initialize to an appropriate value
            List<Channel> actual;
            actual = target.GetAllChannels();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetChannelsByLanguage
        ///</summary>
        [TestMethod()]
        public void GetChannelsByLanguageTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            string language = string.Empty; // TODO: Initialize to an appropriate value
            List<Channel> expected = null; // TODO: Initialize to an appropriate value
            List<Channel> actual;
            actual = target.GetChannelsByLanguage(language);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetChannelsBySearch
        ///</summary>
        [TestMethod()]
        public void GetChannelsBySearchTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            string searchCriteria = string.Empty; // TODO: Initialize to an appropriate value
            List<Channel> expected = null; // TODO: Initialize to an appropriate value
            List<Channel> actual;
            actual = target.GetChannelsBySearch(searchCriteria);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetChannelsByTags
        ///</summary>
        [TestMethod()]
        public void GetChannelsByTagsTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            string commaSeperatedTagsList = string.Empty; // TODO: Initialize to an appropriate value
            List<Channel> expected = null; // TODO: Initialize to an appropriate value
            List<Channel> actual;
            actual = target.GetChannelsByTags(commaSeperatedTagsList);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetChennelByName
        ///</summary>
        [TestMethod()]
        public void GetChennelByNameTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            string name = string.Empty; // TODO: Initialize to an appropriate value
            Channel expected = null; // TODO: Initialize to an appropriate value
            Channel actual;
            actual = target.GetChennelByName(name);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetRelavantChannels
        ///</summary>
        [TestMethod()]
        public void GetRelavantChannelsTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            Channel channel = null; // TODO: Initialize to an appropriate value
            List<Channel> expected = null; // TODO: Initialize to an appropriate value
            List<Channel> actual;
            actual = target.GetRelavantChannels(channel);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for IsChannelNameExists
        ///</summary>
        [TestMethod()]
        public void IsChannelNameExistsTest()
        {
            ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            string channelName = string.Empty; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.IsChannelNameExists(channelName);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for SaveChannel
        ///</summary>
        [TestMethod()]
        public void SaveChannelTest()
        {
            //ChannelManager target = new ChannelManager(); // TODO: Initialize to an appropriate value
            //Channel channel = null; // TODO: Initialize to an appropriate value
            //target.SaveChannel(channel);

            ChannelManager.GetChannelsForMainMenu();

            string errors = ChannelManager.ValidateChannelsXmlFile();

            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }



        /// <summary>
        ///A test for GetChannelsForMainMenu
        ///</summary>
        [TestMethod()]
        public void GetChannelsForMainMenuTest()
        {
            List<Channel> actual;
            actual = ChannelManager.GetChannelsForMainMenu();
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Count > 0);

            XmlSerializer ser = new XmlSerializer(typeof(List<Channel>));

            var fs = File.OpenWrite(@"C:\Channels.xml");

            ser.Serialize(fs, actual);

            fs.Close();

            var fs1 = File.OpenRead(@"C:\Channels.xml");

            List<Channel> channelsFromFile = (List<Channel>) ser.Deserialize(fs1);

        }


        #region Test Data...


        [TestMethod()]
        public void CreateTestDataForDefultCategoryBasedChannels()
        {
            ChannelManager target = new ChannelManager();

            Channel channel = new Channel { Name = "english-topstories", 
                DisplayName= "Top Stories", 
                Query = "(language:english) AND (tags:home OR tags:latest OR tags:braking)", 
                Language = "english",
                ImageUrl = "http://example.com/test.jpg" 
            };
            target.AddChannel(channel);

            channel = new Channel
            {
                Name = "english-business",
                DisplayName = "Top Stories",
                Language = "english",
                Tags= "business",
                ImageUrl = "http://example.com/test.jpg"
            };

            target.AddChannel(channel);

        }


        #endregion

    }
}
